<?php

namespace app\admin\controller;

use app\admin\model\Drawing;
use app\admin\model\Information;
use tools\Http;
use tools\Participle;

/**
 * 其它
 * Class Home
 * @package app\admin\controller
 */
class Other extends Base
{

    //获取关键字
    public function getKeyword(){
        $result = [];//最后返回数组
        $str = input("str/s");
        if(!empty($str)) {//检查字符串是否为空
            $Participle = new Participle();
            $participle = trim($Participle->getParticiple($str));//分词
            if(!empty($participle)) {//检查分词是否为空
                $participleArr = explode(" ", $participle);//转化数组
                if(!empty($participleArr)) {//检查分词数组是否为空
                    $Information = new Information();
                    $keywordsList = collection($Information->keywordsList($participleArr))->toArray();//获取资讯已存在的关键字列表
                    $Drawing = new Drawing();
                    $keywordsList = array_merge($keywordsList,collection($Drawing->keywordsList($participleArr))->toArray());//获取图纸已存在的关键字列表
                    if(!empty($keywordsList)) {//判断是否有关键字
                        foreach ($keywordsList as $val) {//循环获取的关键字
                            $tmp = explode(",", $val["keywords"]);
                            foreach ($tmp as $tval) {
                                if(!empty($tval)) {
                                    if (strpos($str, $tval) !== false) {//判断分词在那个具体的关键字中
                                        $result[] = $tval;
                                    }
                                }
                            }
                        }
                    }
                    if(empty($result)) {
                        $result = $Participle->getParticipleKeyword($str, 10);
                    }else{
                        $result = implode(",",array_unique($result));
                    }
                }
            }
        }
        return $result;
    }

    //地址接口
    public function addressList(){
        $pid = input("pid/d",0);
        $Http = new Http();
        $ImgApiData = config("ImgApiData");//获取接口配置
        $Http->setUrl($ImgApiData["domain"]."/".$ImgApiData["ApiList"]["addressList"]);
        $Http->setData([
            'pid'     => $pid,
        ]);
        $result = $Http->sendRequest();
        $result = json_decode($result,true);
        return json($result["data"]);
    }
}
